package com.huanong.mapper;

import com.huanong.pojo.Product;
import com.huanong.pojo.vo.ProductInsertVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 农业产品相关的Mapper
 */
@Repository
public interface ProductMapper {

    @Select("select * from product")
    @Results({
            @Result(property = "type", column = "types_id",
                    one = @One(select = "com.huanong.mapper.TypesMapper.queryById"))
    })
    List<Product> queryProduct();

    @Select("select * from product where ptid=#{PtId}")
    @Results({
            @Result(property = "type", column = "types_id",
                    one = @One(select = "com.huanong.mapper.TypesMapper.queryById"))
    })
    Product queryProductById(@Param("PtId") Integer PtId);

    @Insert("insert into product (ptpictureurl,ptname,ptvalue,ptuse,ptmessage,ptprice,types_id) values(#{PtPictureUrl},#{PtName},#{PtValue},#{PtUse},#{PtMessage},#{PtPrice},#{TsId})")
    int addProduct(ProductInsertVo product);

    @Delete("delete from product where ptid=#{PtId}")
    int deleteProduct(@Param("PtId") Integer PtId);

    @Update("update product set ptpictureurl=#{PtPictureUrl},ptname=#{PtName},ptvalue=#{PtValue},ptuse=#{PtUse},ptmessage=#{PtMessage} where ptid=#{PtId}")
    int updateProduct(ProductInsertVo product);

    @Select("select * from product where types_id = #{tsId}")
    @Results({
            @Result(property = "type", column = "types_id",
                    one = @One(select = "com.huanong.mapper.TypesMapper.queryById"))
    })
    List<Product> queryProductByClassifyId(@Param("tsId") Integer tsId);
}
